<?php
/**
 * Created By virus_cms
 * Author: Virus
 * Date: 2020/2/29
 * Time: 11:56
 */

declare(strict_types=1);

namespace app\admin\middleware;


class Auth
{
    /**
     * 中间件判断是否登录
     * @param $request
     * @param \Closure $next
     * @return mixed|\think\response\Redirect
     */
    public function handle($request, \Closure $next)
    {
        if (empty(session('session_admin')) && !preg_match("/login/", $request->pathinfo())) {
            return redirect((string)url('login/index'));
        }

        $response = $next($request);

        return $response;
    }
}